//
//  WmcTeamLocationView.swift
//  YPWatermarkCamera
//
//  Created by yupao_ios_macmini06 on 2022/9/21.
//

import UIKit

class WmcTeamLocationView: WmcBaseView {
    // Internal
    func configure(model: WmcMediaTeamResourceModel) {
        self.model = model
        if model.area.isEmpty {
            addressLabel.text = "未获取到地点信息"
            arrowImageView.isHidden = true
        } else {
            addressLabel.text = model.area
            arrowImageView.isHidden = false
        }
    }

    var location: String? {
        didSet {
            guard let location = location else {
                return
            }
            addressLabel.text = location
        }
    }

    // Private

    private lazy var locationImageView: UIImageView = {
        let imageView = UIImageView(image: "location_icon".wmc_image)
        imageView.yp.set(tintColor: UIColor.wmc_grayH5_606066)
        return imageView
    }()

    private lazy var addressLabel: UILabel = {
        let label = UILabel()
        label.textColor = .wmc_grayH5_606066
        label.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        return label
    }()

    private lazy var arrowImageView: UIImageView = {
        let imageView = UIImageView(image: "arrow_right".wmc_image)
        imageView.yp.set(tintColor: UIColor.wmc_grayH5_606066)
        return imageView
    }()

    lazy var button: UIButton = {
        let view = UIButton()
        view.backgroundColor = .clear
        return view
    }()

    private var model: WmcMediaTeamResourceModel?

    override func makeUI() {
        backgroundColor = .wmc_white_FFFFFF

        addSubview(locationImageView)
        addSubview(addressLabel)
        addSubview(arrowImageView)

        locationImageView.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.centerY.equalToSuperview()
            make.width.height.equalTo(18)
        }

        addressLabel.snp.makeConstraints { make in
            make.left.equalTo(locationImageView.snp.right).offset(1)
            make.centerY.equalToSuperview()
            // make.width.lessThanOrEqualTo(maxWidth)
        }

        arrowImageView.snp.makeConstraints { make in
            make.left.equalTo(addressLabel.snp.right).offset(1)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(12)
            make.right.lessThanOrEqualToSuperview()
        }
        /// 手势不起作用
        addSubview(button)
        button.snp.makeConstraints { make in
            make.top.left.right.bottom.equalToSuperview()
            make.height.equalTo(16)
        }
    }
}
